/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package common;

import java.io.File;
import java.io.InputStream;
import java.net.Socket;

/**
 *
 * @author Mateusz
 */
public class FileReceiver implements Runnable {

    private Socket socket;
    private File file;

    public void start(Socket listener, File file) {
        this.file = file;

        FileReceiver file_rec = new FileReceiver();
        file_rec.socket = listener;
        new Thread(file_rec).start();

    }

    public void run() {
        try {
            InputStream in = socket.getInputStream();
            ByteStream.toFile(in, file);
        } catch (java.lang.Exception ex) {
            ex.printStackTrace(System.out);
        }
    }
}
